package com.cloudfun.campusshare.entity;

import com.cloudfun.campusshare.common.constant.ApplicationResult;
import com.cloudfun.campusshare.common.constant.ApplicationStatus;
import com.cloudfun.campusshare.common.constant.ApplicationType;
import lombok.*;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;

/**
 * Created by Huqin on 2019/12/30
 */
@Data
@Entity
@Builder
@ToString(exclude = {"applicant", "auditor"})
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "application")
public class ApplicationEntity extends BaseEntity {

    @Id
    @GenericGenerator(name = "id_uuid", strategy = "uuid")
    @GeneratedValue(generator = "id_uuid")
    @Column(name = "id", nullable = false, unique = true, length = 40)
    private String id;

    @Column(columnDefinition = ("varchar(32) not null comment '类型'"))
    @Enumerated(EnumType.STRING)
    private ApplicationType type;

    @Column(columnDefinition = ("varchar(40) not null comment '业务id'"))
    private String bizId;

    @Column(name = "applicant_id", columnDefinition = ("varchar(40) not null comment '申请人Id'"))
    private String applicantId;

    @ManyToOne
    @JoinColumn(name = "applicant_id", updatable = false, insertable = false)
    private UserEntity applicant;

    @Column(name = "auditor_id", columnDefinition = ("varchar(40) not null comment '审批人Id'"))
    private String auditorId;

    @ManyToOne
    @JoinColumn(name = "auditor_id", insertable = false, updatable = false)
    private UserEntity auditor;

    @Column(columnDefinition = ("varchar(1024) default null comment '内容'"))
    private String content;

    @Column(columnDefinition = ("varchar(32) not null comment '状态'"))
    @Enumerated(EnumType.STRING)
    private ApplicationStatus status;

    @Column(columnDefinition = ("varchar(32) null comment '结果'"))
    @Enumerated(EnumType.STRING)
    private ApplicationResult result;

    @Column(columnDefinition = ("tinyint(1) not null comment '伪删'"))
    private Boolean enabled;

    @Column(columnDefinition = "varchar(14) default null comment '申请时间'")
    private String applyTime;

}
